package my.edu.utils;

import my.edu.common.constant.MessageConstant;
import my.edu.common.domain.OrderProductDetail;
import my.edu.common.exception.Order.SalesException;

import java.math.BigDecimal;

public class OrderDetailServiceUtil {
    public static void setAmount(OrderProductDetail orderDetail) {
        BigDecimal amountAfterDiscount = orderDetail.getCurrentPrice().subtract(orderDetail.getDiscountAmount());
        if (amountAfterDiscount.compareTo(BigDecimal.ZERO)<0)throw new SalesException(MessageConstant.AMOUNT_ERROR);
        //设置优惠后金额
        orderDetail.setAmountAfterDiscount(amountAfterDiscount);
        //设置含税价
        orderDetail.setTaxInclusivePrice(amountAfterDiscount.add(orderDetail.getTaxAmount()));
        //设置价税总计金额
        orderDetail.setPriceTaxTotal( orderDetail.getTaxInclusivePrice().multiply(BigDecimal.valueOf(orderDetail.getQuantity())));
    }
}
